package com.baboba.rummy.web.client.card;

import com.baboba.rummy.card.UserCard;
import com.baboba.rummy.web.client.common.DragDropContext;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.DragEndEvent;
import com.google.gwt.event.dom.client.DragEndHandler;
import com.google.gwt.event.dom.client.DragStartEvent;
import com.google.gwt.event.dom.client.DragStartHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;

public class CardView extends Composite {
    private UserCard card;
	
    public CardView(UserCard card){
    	this.card = card;
    	
        Label label = new Label();
        label.setText(String.valueOf(card.getNumber()));
        label.setStylePrimaryName("card");
        
        if (card.getNumber()>0)
        label.addStyleName("card_"+ card.getColor());
        
        label.getElement().setDraggable(Element.DRAGGABLE_TRUE);
        label.addDragStartHandler(new DragStartHandler() {
			@Override
			public void onDragStart(DragStartEvent event) {
				DragDropContext.setDragSourceWiget(CardView.this);
			}
		});
        label.addDragEndHandler(new DragEndHandler() {

			@Override
			public void onDragEnd(DragEndEvent event) {
				System.out.println("Drag end");
			}

		});
        
        this.initWidget(label);
    }

	public UserCard getCard() {
		return card;
	}
    
}